import Trans from "~/utils/sycm/trans";

export class SycmTableUtils {
    static tranNumber(showZs: boolean = false, text: any, fractionDigits: number = 0, format: boolean = true) {
        if (showZs) {
            return text;
        }
        const price = Trans.number(text).toFixed(fractionDigits);
        if (price === 'NaN') {
            return '0';
        }
        if (!format) {
            return price;
        }
        // 每隔三位加逗号
        return price.replace(/\B(?=(\d{3})+(?!\d))/g, ',');
    }

    static tranRatio(showZs: boolean = false, text: any) {
        if (showZs) {
            return String(text);
        }
        if (isNaN(text) || !text) {
            return '0.00%';
        }
        return Trans.ratio(text);
    }
}
